#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int M = 1e6+10;
const int N = 2e4+10;

int s[N],cnt[M],id[N],rk[N],ork[N<<1],k,n,sa[N],px[N],m,ht[N],ans;
multiset<int> st;

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in-1; m = 1e6;
	for(int i = 1;i <= n;i++) s[i] = in;
	for(int i = 1;i <= n;i++) ++cnt[rk[i] = s[i]];
	for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
	for(int i = n;i >= 1;i--) sa[cnt[rk[i]]--] = i;
	for(int h = 1,p;h <= n;h <<= 1,m = p){
		p = 0;for(int i = n;i > n-h;i--) id[++p] = i;
		for(int i = 1;i <= n;i++) if(sa[i] > h) id[++p] = sa[i] - h;
		for(int i = 1;i <= m;i++) cnt[i] = 0;
		for(int i = 1;i <= n;i++) ++cnt[px[i] = rk[id[i]]];
		for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
		for(int i = n;i >= 1;i--) sa[cnt[px[i]]--] = id[i];
		for(int i = 1;i <= n;i++) ork[i] = rk[i];
		p = 0;
		for(int i = 1;i <= n;i++)
			rk[sa[i]] = (ork[sa[i]] == ork[sa[i-1]] && ork[sa[i]+h] == ork[sa[i-1]+h]) ? p : ++p;
	}
	for(int i = 1,p = 0;i <= n;i++){
		if(p) p--;
		while(s[i+p] == s[sa[rk[i]-1]+p]) p++;
		ht[rk[i]] = p;
	}
	for(int i = 1;i <= n;i++){st.insert(ht[i]);
		if(i > k) st.erase(st.find(ht[i-k]));
		if(i >= k) ans = max(ans,*st.begin());
	}printf("%d\n",ans);
	return 0;
}

